<?php

class Math
{

    public function getMultiplyClass() {
        return new class() extends Math
        {

            public function multiply($a, $b) {
                return $a * $b;
            }
        };
    }

}

echo (new Math())->getMultiplyClass()->multiply(2, 3);